/***********************************************************************
 * Module:  Matiere.java
 * Author:  Alexandro
 * Purpose: Defines the Class Matiere
 ***********************************************************************/

package dao;

import java.util.*;
import java.sql.*;

public class Matiere extends Codage implements InterfaceDAO {
   private int coefficient;
   
   public Epreuve[] totalEpreuves;
   
   public int getCoefficient() {
      return coefficient;
   }
   
   /** @param newCoefficient */
   public void setCoefficient(int newCoefficient) {
      coefficient = newCoefficient;
   }
   
   public int insert(int[] params) {
      
      
       
        try {			
			dao.DAODataConnection.executer("INSERT INTO matiere(cod_mat,code_mod,libelle,coefficient)"+
										   "VALUES("+getCode()+","+params[0]+",'"+getLibelle()+"',"+getCoefficient()+ ");");											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
		
   }
   
   public Object[] select(int[] param) {
      
       
       try {			
			
			ResultSet table = dao.DAODataConnection.executerQuery("SELECT * FROM matiere");											
			Vector sortie = new Vector();			
			while(table.next() )	
			{
				Matiere neuf = new Matiere();
				neuf.setCode(table.getInt(1));
				neuf.setLibelle(table.getString(3));				
				neuf.setCoefficient(table.getInt(4));				
				
				sortie.add(neuf);				
			}		
			return sortie.toArray();			
			}
			
		catch(Exception e){ System.out.println(e); }		
		
		return null;
		
		
   }
   
   public int delete(int[] params) {
      
      
      try {			
			dao.DAODataConnection.executer("DELETE FROM matiere WHERE cod_mat="+getCode()+" and code_mod="+params[0]);											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }
   
   public int update(int[] params) {
      
      
       try {			
			dao.DAODataConnection.executer("UPDATE matiere SET "+										   
										   "libelle='"+getLibelle()+"',"+
										   "coefficient="+getCoefficient()+ " where cod_mat="+getCode()+" and code_mod="+params[0]);											
			return 0;			
			}		
		catch(Exception e){ System.out.println(e); }		
		
		return 1;
		
   }

}